#ifndef XRN_TYPEDEF_H 
#define XRN_TYPEDEF_H
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>

#define XRN_SUBJECT_CERTIFICATE_LENGTH 512

#define XRN_BUFF_SIZE 256

#define XBIT_TYPE bool

#define XRN_ENC_PASS_BUFF_SIZE 256


#define XRN_BUFFER_ENC_BIST_SIZE 128

#define XSUCCESS ( 0x00000000 )

#define XRN_MAX_MERGE_PARALLELISM 64

typedef enum {
    std_parameters = 0,
    xrn_parameters = 1,
    std_parameters_plus_password = 2,
    xrn_parameters_plus_password = 3,
    std_parameters_plus_file = 4,
    xrn_parameters_plus_file = 5,
    no_encoding = 6
} xrn_encoding_mode_t;

typedef enum {
    xrn_automatic = 0, 
    xrn_manual = 1,
} xrn_check_initialization_mode_t;

typedef enum {
    c_genesis                = 0,
    c_base                   = 1,
    c_vector                 = 2,
    c_matrix                 = 3,
    c_matrix_compressed      = 4,
    c_start                  = 5,
    c_monomial_key           = 6,
    c_binomial_key           = 7,
    c_point                  = 8,
    c_hash                   = 9,
    c_signature_sym          = 10,
    c_signature_asy          = 11,
    c_ring_signature         = 12,
    c_certificate_sym        = 13,
    c_certificate_asy        = 14,
    c_monomial_commitment    = 15,
    c_binomial_commitment    = 16,
    c_monomial_response      = 17,
    c_monomial_proof         = 18,
    c_polyvalent_proof       = 19,
    c_polyvalent_key         = 20,
    c_monovalent_key         = 21,
    c_challenge              = 22,
    c_solution               = 23,
    c_sym_encryption         = 24,
    c_asy_encryption         = 25
} xrn_lib_xtype_t;

typedef struct xrn_log_t {

    FILE * err_fp  ;
    FILE * war_fp  ;
    FILE * not_fp  ;
    FILE * deb_fp  ;
    uint8_t err_en ;
    uint8_t war_en ;
    uint8_t not_en ;
    uint8_t deb_en ;
    uint32_t deb_seed ;
    uint32_t war_shown;
} xrn_log_t;

typedef struct xrn_crypto_lib_header_t {

    uint8_t encoding_guard[256] ;
    uint32_t magic_number       ;
    uint32_t version            ;
    uint32_t reserved_0         ;
    uint32_t reserved_1         ;
    uint8_t type                ;
    uint8_t state_size          ;
    uint16_t crc16;
} xrn_crypto_lib_header_t;

typedef struct xrn_encoding_checks_t {
    uint8_t index;
    uint8_t buffer[XRN_BUFFER_ENC_BIST_SIZE];
    uint8_t buffer_full;
    uint8_t check_running_error_en;
    uint8_t check_disparity_error_en;
    uint32_t max_consecutives_01s_threshold_error;
    uint32_t max_consecutives_01s_threshold_warning;
    uint32_t max_number_of_01s_threshold_error;
    uint32_t max_number_of_01s_threshold_warning;
    uint32_t count_1;
    uint32_t count_0;
    uint32_t count_consecutive_1;
    uint32_t count_consecutive_0;
    uint32_t max_consecutive_1;
    uint32_t max_consecutive_0;
} xrn_encoding_checks_t;

typedef struct xrn_encoding_param_t {
    uint8_t table[256];
    uint64_t prng_state[4];
    xrn_encoding_checks_t prob_checks;
} xrn_encoding_param_t;

typedef struct xrn_encoding_tmp_param_t {
    int i,j,k,ret,final_ret;
    uint8_t hidden_index_prng, hidden_index_input;
    uint8_t exposed_data_prng, hidden_data_input;
    uint8_t pseudo_random_seed;
    uint64_t t;
    uint8_t byte_tmp;
} xrn_encoding_tmp_param_t;

typedef struct xrn_encoding_settings_t {
    FILE * encoding_parameters_fp;
    FILE * initialization_file_fp;
    xrn_encoding_mode_t mode;
    char password[XRN_ENC_PASS_BUFF_SIZE];
    uint16_t password_length;
    xrn_check_initialization_mode_t check_mode;
    uint8_t check_running_error_en;
    uint8_t check_disparity_error_en;
    uint32_t max_consecutives_01s_threshold_error;
    uint32_t max_consecutives_01s_threshold_warning;
    uint32_t max_number_of_01s_threshold_error;
    uint32_t max_number_of_01s_threshold_warning;
} xrn_encoding_settings_t;

typedef struct xrn_interface_settings_t {
     xrn_encoding_settings_t i_settings;
     xrn_encoding_settings_t o_settings;
} xrn_interface_settings_t;

typedef struct xrn_crypto_extra_settings_t {
    char rnd_str[XRN_BUFF_SIZE];
    uint8_t crc_bytes;
    uint8_t state_size;
    uint8_t thread_enable;
    uint32_t component_id;
    XBIT_TYPE const_exec_time;
    xrn_interface_settings_t encoding_settings;
} xrn_crypto_extra_settings_t;

typedef struct xblock_settings_t {
   XBIT_TYPE all;
   uint64_t start_block;
   uint64_t end_block;
} xblock_settings_t;

#endif
